import { ADD_USERNAME } from '../consts'
import axios from 'axios'
import { message } from 'antd'
export let addUsername = data => ({ type: ADD_USERNAME, data })


export let login = data => dispatch => {
    axios.post('/login', data)
        .then(({ data }) => {
            if(!data.errno) {
                dispatch(addUsername(data.data))
            }else {
                message.error('登陆异常, 请检查用户名和密码')
            }
        })
 }

export let userInfo = data => dispatch => {
    axios.get('/userInfo')
    .then(({ data }) => {
        if(!data.errno) {
            dispatch(addUsername(data))
        }
    })

}